﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;

namespace AdminModule.UserControls.DataInput
{
    public partial class DatePicker : UserControl
    {
        public event RoutedEventHandler ResetButtonClick;

        public DatePicker()
        {
            InitializeComponent();
            this.button.Click += (s, ev) =>
                {
                    if (ResetButtonClick != null) ResetButtonClick(this, ev);
                };
        }

        public DateTime? SelectedDate
        {
            get
            {
                return (DateTime?)GetValue(SelectedDateProperty);
                //return (DateTime?)this.picker.GetValue(System.Windows.Controls.DatePicker.SelectedDateProperty);
            }
            set
            {
                SetValue(SelectedDateProperty, value);
                //this.picker.SetValue(System.Windows.Controls.DatePicker.SelectedDateProperty, value);
            }
        }

        public static readonly DependencyProperty SelectedDateProperty =
            DependencyProperty.Register("SelectedDate", typeof(DateTime?), typeof(AdminModule.UserControls.DataInput.DatePicker), new PropertyMetadata(SelectedDateChanged));

        private static void SelectedDateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (e.OldValue != null) return;
            AdminModule.UserControls.DataInput.DatePicker t = d as AdminModule.UserControls.DataInput.DatePicker;
            t.picker.SetValue(System.Windows.Controls.DatePicker.SelectedDateProperty, e.NewValue);
        }

        public System.Windows.Controls.DatePicker Picker
        {
            get { return this.picker; }
        }

        public Button Button
        {
            get { return this.button; }
        }
    }
}
